package com.leetcode.partition11;

import java.io.*;
import java.util.Arrays;

/**
 * @author `RKC`
 * @date 2022/2/10 23:49
 */
public class LC1042不邻接植花 {

    private static final int N = 10010, M = 40010;
    private static int[] head = new int[N], ver = new int[M], next = new int[M];
    private static boolean[][] st = new boolean[N][5];

    private static int n = 0, m = 0, idx = 0;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] ss = reader.readLine().split(" ");
        int n = Integer.parseInt(ss[0]), m = Integer.parseInt(ss[1]);
        int[][] paths = new int[m][2];
        for (int i = 0; i < m; i++) {
            ss = reader.readLine().split(" ");
            int a = Integer.parseInt(ss[0]), b = Integer.parseInt(ss[1]);
            paths[i] = new int[]{a, b};
        }
        writer.write(Arrays.toString(gardenNoAdj(n, paths)));
        writer.flush();
    }

    public static int[] gardenNoAdj(int _n, int[][] paths) {
        n = _n;
        m = paths.length;
        int[] answer = new int[n];
        int cnt = 0;
        Arrays.fill(head, -1);
        for (int[] path : paths) {
            int u = path[0], v = path[1];
            add(u, v);
            add(v, u);
        }
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= 4; j++) {
                if (!st[i][j]) {
                    answer[cnt++] = j;
                    for (int k = head[i]; k != -1; k = next[k]) {
                        int v = ver[k];
                        st[v][j] = true;
                    }
                    break;
                }
            }
        }
        return answer;
    }

    private static void add(int a, int b) {
        ver[idx] = b;
        next[idx] = head[a];
        head[a] = idx++;
    }
}
